package com.example.userdemo.service.impl;

import com.example.userdemo.model.User;
import com.example.userdemo.repository.UserRepository;
import com.example.userdemo.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Optional;

@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private UserRepository userRepository;

    @Override
    public Page<User> getAllUsers(Page<User> page, QueryWrapper<User> wrapper) {
        return userRepository.selectPage(page, wrapper);
    }

    @Override
    public User getUserById(Long id) {
        return userRepository.selectById(id);
    }

    @Override
    public User createUser(User user) {
        userRepository.insert(user);
        return user;
    }

    @Override
    public User updateUser(User user) {
        userRepository.updateById(user);
        return user;
    }

    @Override
    public void deleteUser(Long id) {
        userRepository.deleteById(id);
    }
}
